import java.util.concurrent.ThreadLocalRandom;

public class arraydemo {


    public static void main(String[] args) {
        int[] nums = {43,12,54,11,67,88,6};
        System.out.println(randomFind(nums));
        insert(nums,10,2);
        printArray(nums);
        deleteArray(nums, 2);
        printArray(nums);
        System.out.println(find(nums,88));
        nums =extend(nums, 20);
        System.out.println(nums.length);
              
    }

    public static int randomFind(int[] nums){
        int randomIndex = ThreadLocalRandom.current().nextInt(0,nums.length);
        int randomNums=nums[randomIndex];
        return randomNums;
    }

    public static void insert(int[] nums, int num ,int index){
        for(int i=nums.length-1;i>index;i--) {
            nums[i]=nums[i-1];
        }
        nums[index]=num;
    }

    public static void deleteArray(int[] nums, int index){
        for(int i=index;i<nums.length-1;i++) {
            nums[i]=nums[i+1];
        }
    }
   /**
    * 
    * @param nums
    * @param target
    * @return int
    * @apiNote:遍历查找
    */
    public static int find(int[] nums, int target){
        for(int i=0;i<nums.length;i++) {
            if (nums[i]==target) return i;
        }
        return -1;
    }
    /**
     * 
     * @param nums 原数组
     * @param enlarge 扩充个数
     * @return int[]:新数组
     */
    public static int[] extend(int[] nums,int enlarge){
        int[] res = new int[nums.length+enlarge];
        for(int i=0;i<nums.length;i++){
            res[i]=nums[i];
        }
        // nums = res;
        return res;
    }
    
    public static void printArray(int[] nums){
        for(int i =0;i<nums.length;i++){
            System.out.print(nums[i]+" ");
        }
        System.out.println();
    }
}